package com.supply.supplymanage.biz;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.supply.supplymanage.dao.ConSeleMapper;
import com.supply.supplymanage.util.*;
import freemarker.template.utility.DateUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class ConSeleBizImpl implements ConSeleBiz {

    @Resource
    ConSeleMapper conSeleMapper;

    //得到随机数开发单号
   public  Map selConAll(){

       /*DtaeUtil dtaeUtil = new DtaeUtil();
       String s = dtaeUtil.currDate();
       不能加 加的话  java.lang.OutOfMemoryError: Java heap space
       内存溢出
       */
       String s = DtaeUtil.genOrderId();



       Map map = new HashMap();
       List<Map> seleclient = conSeleMapper.seleclient();
       List<Map> seleplate = conSeleMapper.seleplate();
       List<Map> seleseason = conSeleMapper.seleseason();
       List<Map> selebrand = conSeleMapper.selebrand();
       List<Map> selestylehao = conSeleMapper.selestylehao();
       map.put("uuid",s);
       map.put("stylehaoss",selestylehao);
       map.put("clientss",seleclient);
       map.put("platess",seleplate);
       map.put("seasonss",seleseason);
       map.put("brandss",selebrand);
       System.out.println(map);

       return map;
    }
    //根据款号查款式
    public List<Map> seledesign(int haoid) {

        return conSeleMapper.seledesign(haoid);
    }
    //查询所选的尺码大小信息 暂时抛弃
    public List<Map> seleSize(int[] chval) {

        return conSeleMapper.seleSize(chval);
    }
    //查询所有尺码
   public  List<Map> seleAllsize(){
       List<Map> maps = conSeleMapper.seleAllsize();
       return maps;
    }
    //查询所有未停用颜色
    public PageInfo seleTinct(int PageNum,String typecolor,String colorname){
        PageHelper.startPage(PageNum,2);
        List<Map> maps = conSeleMapper.seleTinct(typecolor,colorname);
        System.out.println(maps);

        PageInfo<Map> pageInfo=new PageInfo<Map>(maps);

        return pageInfo;
    }
    //根据款式查出所需服装部位
    public List<Map> selecloth(int designid){
       return conSeleMapper.selecloth(designid);
    }


    //查询颜色类别
    public List<Map> seleTincttype(){
       return conSeleMapper.seleTincttype();
    }
    //查询所有物料信息
    public PageInfo selesuppliesdeta(int PageNum,String bomgys, String bomwlname,String bomcolor){
        System.out.println(conSeleMapper.selesuppliesdeta(bomgys,bomwlname,bomcolor));
        PageHelper.startPage(PageNum,4);
        List<Map> selesuppliesdeta = conSeleMapper.selesuppliesdeta(bomgys,bomwlname,bomcolor);
        System.out.println(selesuppliesdeta);
        PageInfo<Map> pageInfo=new PageInfo<Map>(selesuppliesdeta);
        return pageInfo;
    }
    //添进数据库
    public void insertTemp(JsonAll jsonAll){
       //开发订单
        OrderUtil orderUtil = jsonAll.getOrderUtil();

        //返回其主键
        conSeleMapper.insertOrd(orderUtil);
        //插入数据库主键的值
        Integer eorid=orderUtil.getEorid();

        OrderInfoUtil InfoUtil=jsonAll.getOrderInfoUtil();
        InfoUtil.setEorid(eorid);
        //插入明细表
        conSeleMapper.insertOrdInfo(InfoUtil);
        //开发明细ID
        Integer infoid=InfoUtil.getEoinfoid();
        //添加细码表
        List<ChicaUtil> chicaUtil = jsonAll.getChicaUtil();
        for (ChicaUtil a:
             chicaUtil) {
            a.setEoinfoid(infoid);
            conSeleMapper.insertChica(a);
        }
        //添加用料表
        List<SupUtil> supUtil = jsonAll.getSupUtil();
        for (SupUtil sup:
             supUtil) {
            sup.setEoinfoid(infoid);
            conSeleMapper.insertSup(sup);
        }


    }



    @Override
    public List<Map> seleclient() {
        return null;
    }

    @Override
    public List<Map> seleseason() {
        return null;
    }

    @Override
    public List<Map> seleplate() {
        return null;
    }
    @Override
    public List<Map> selebrand() {
        return null;
    }
    @Override
    public List<Map> selestylehao() {
        return null;
    };
}
